<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="../style/api.css" />
    <link rel="stylesheet" type="text/css" href="../style/head.css" />
    <style>
        #closeIt {
            position: absolute;
            top: 35px;
            left: 1rem;
            width: 2rem;
            height: 2rem;
        }
        main {
            padding-top: 75px;
        }
        .updateBox {
            padding: 0.5rem;
            background-color: #fff;
        }
        input {
            width: 100%;
            margin: 0.5rem 0;
            padding: 1rem;
            outline: none;
            border-bottom: 1px solid #f2f2f2;
        }
        .modify {
            padding: 1rem;
            color: #fff;
            text-align: center;
            border-radius: 0.4rem;
            background-color: #3949AB;
        }
    </style>
</head>

<body>
  <header>
    修改密码
    <img src="../img/icons/back.png" alt="" onclick="api.closeWin()" id="closeIt">
  </header>
  <main>
      <div class="updateBox">
          <input type="password" placeholder="输入新密码" id="pwd">
          <input type="password" placeholder="确认新密码" id="pwd2">
          <div class="modify">更改</div>
      </div>
  </main>
</body>
<script type="text/javascript" src="../js/api.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
    apiready = function() {

    };

    $('.modify').click(function() {
        var pwd = $('#pwd').val();
        var pwd2 = $('#pwd2').val();
        var userid = $api.getStorage('userid');

        if(!pwd || $.trim(pwd).length == 0) {
            api.toast({
                msg: '未输入新密码',
                duration: 2000,
                location: 'bottom'
            });
            return
        };

        if(!pwd2 || $.trim(pwd2).length == 0) {
            api.toast({
                msg: '未确认新密码',
                duration: 2000,
                location: 'bottom'
            });
            return
        };

        if(pwd != pwd2) {
          api.toast({
              msg: '两次输入不一致',
              duration: 2000,
              location: 'bottom'
          });
          return
        };

        api.ajax({
            url: 'http://114.116.243.15/newbtb/appinfo/update.lecture',
            method: 'post',
            data: {
              body: {
                  'tbname': 'lecture_user',
                  'id': userid,
                  'lecture_password': pwd
              }
            }
        },function(ret, err){
            if (ret) {
                if(ret.status == 1) {
                    api.toast({
                        msg: '修改成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    setTimeout(function() {
                        api.openWin({
                            name: 'login',
                            url: './btb-login.html',
                            slidBackEnabled: false
                        });
                    },1000)
                }
            }
        });

    })
</script>

</html>
